package com.atguigu.srb.core;

import com.alibaba.fastjson.JSON;
import com.atguigu.srb.base.util.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class YunMusicUtils {
    @Test
    public void test(){
        //服务器地址  推荐歌单
        String host = "http://cloud-music.pl-fe.cn";
        //资源路径
        String path = "/personalized";
        //请求方式
        String method = "GET";
        Map<String, String> headers = new HashMap<String, String>();
        //请求参数：
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("limit", "15");

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString());
            //获取response的body: 解析响应体
            String resultJson = EntityUtils.toString(response.getEntity(), "UTF-8");
            System.out.println(resultJson);
//            Map map = JSON.parseObject(resultJson, Map.class);
//            String resultCode = map.get("error_code").toString();
//            if("0".equals(resultCode)){
//                //短信发送成功
//                System.out.println("短信发送成功:"+resultJson);
//            }else{
//                //短信发送失败
//                System.out.println("短信发送失败，原因："+ resultJson);
//            }
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
